package cn.itcast.order.service;


import cn.itcast.feign.clients.UserClient;
import cn.itcast.feign.pojo.User;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
import org.springframework.cloud.openfeign.FeignClientFactoryBean;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserClient userClient;


    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

//        FeignClientFactoryBean t;
//        LoadBalancerInterceptor t;
//
//        String url = "http://user-server/user/"+order.getUserId();
//
//        User user = restTemplate.getForObject(url, User.class);
        User user = userClient.queryById(order.getUserId());

        order.setUser(user);
        // 4.返回
        return order;
    }
}
